package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaEducationDao;
import com.example.informationEntry.entity.NaEducation;
import com.example.informationEntry.service.NaEducationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学历信息表(NaEducation)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naEducationService")
public class NaEducationServiceImpl implements NaEducationService {
    @Resource
    private NaEducationDao naEducationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param educationNumber 主键
     * @return 实例对象
     */
    @Override
    public NaEducation queryById(String educationNumber) {
        return this.naEducationDao.queryById(educationNumber);
    }

    /**
     * 查询多条数据
     *
     * @param academicName 学历中文
     * @return 对象列表
     */
    @Override
    public List<NaEducation> queryAllByName(String academicName) {
        return this.naEducationDao.queryAllByName(academicName);
    }

    /**
     * 查询多条数据
     *
     * @param naEducation 实例对象
     * @return list集合
     */
    @Override
    public List<NaEducation> queryAll(NaEducation naEducation) {
        return this.naEducationDao.queryAll(naEducation);
    }

    /**
     * 新增数据
     *
     * @param naEducation 实例对象
     * @return 实例对象
     */
    @Override
    public NaEducation insert(NaEducation naEducation) {
        this.naEducationDao.insert(naEducation);
        return naEducation;
    }

    /**
     * 修改数据
     *
     * @param naEducation 实例对象
     * @return 实例对象
     */
    @Override
    public NaEducation update(NaEducation naEducation) {
        this.naEducationDao.update(naEducation);
        return this.queryById(naEducation.getEducationNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param educationNumber 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String educationNumber) {
        return this.naEducationDao.deleteById(educationNumber) > 0;
    }

    /**
     * 转换map  K为ID  V为转换值
     *
     * @return 可作为转换的map
     */
    @Override
    public Map<String, String> queryNumberToName() {
        Map<String, String> resultMap = new HashMap<>();
        List<NaEducation> naEducationsList = this.queryAll(new NaEducation());
        for (NaEducation education : naEducationsList) {
            resultMap.put(education.getEducationNumber(), education.getAcademicName());
        }
        return resultMap;
    }
}